﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;
namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllPRDetailsbyPRIDDataAction : BestLifeDataAction<List<Purchase_Request>>
    {
        private string GvPriId;
        public BestLifeGetAllPRDetailsbyPRIDDataAction(string PPriId)
        {
            GvPriId = PPriId;
        }

        public override List<Purchase_Request> Body(SqlConnection PConn)
        {
            try
            {
                List<Purchase_Request> LvList = new List<Purchase_Request>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetPRDetailsByPRID";
                LvCommand.Parameters.Add(new SqlParameter("@PRID", GvPriId));
                

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Purchase_Request LvAPR = new Purchase_Request();
                    LvAPR.Pr_Id = LvReader.GetValue(0).ToString();
                    LvAPR.Qty = decimal.Parse(LvReader.GetValue(1).ToString());
                    LvAPR.PL_Id =LvReader.GetValue(2).ToString();
                    //LvAPR.Description =LvReader.GetValue(3).ToString();
                    //LvAPR.Total =decimal.Parse(LvReader.GetValue(4).ToString());
                    
                    //LvSubCategory.Description = LvReader.GetValue(4).ToString();
                    //LvSubCategory.Status = LvReader.GetValue(5).ToString();

                    LvList.Add(LvAPR);
                }


                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
